<?php
class FavoritesController extends Controller{
	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('index','discover','share'),
				'users'=>array('@'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	public function actionIndex(){
		$dataProvider = new CActiveDataProvider('Actions',array(
			'criteria'=>array(
				'condition'=>'user_id='.Yii::app()->user->id,
				'order'=>'action_time DESC',
			),
		));
		$newsDataProvider = News::dataProvider($dataProvider,'news_id');
		//用户信息
		$user = User::model()->findByPk(Yii::app()->user->id);
		$this->render('index',array('dataProvider'=>$newsDataProvider,'user'=>$user));
	}
	
	public function actionDiscover(){
		$dataProvider = new CActiveDataProvider('News',array(
			'criteria'=>array(
				'condition'=>'user_id='.Yii::app()->user->id,
				'order'=>'post_time DESC',
			),
		));
		//用户信息
		$user = User::model()->findByPk(Yii::app()->user->id);
		$this->render('discover',array('dataProvider'=>$dataProvider,'user'=>$user));
	}

	public function actionShare(){
		$dataProvider = new CActiveDataProvider('Actions',array(
			'criteria'=>array(
				'condition'=>'user_id='.Yii::app()->user->id . " and action_type='digg'",
				'order'=>'action_time DESC',
			),
		));
		$newsDataProvider = News::dataProvider($dataProvider,'news_id');
		//用户信息
		$user = User::model()->findByPk(Yii::app()->user->id);
		$this->render('share',array('dataProvider'=>$newsDataProvider,'user'=>$user));
	}
}